const got =require("got")
var token=require("./token.js");
const config=require("./config.js");

class DB{
	constructor(){
		this.env=config.env;
		this.token=token
	}


	async add(_collection,_data={}){
		var token= await this.token
		var data={data:_data}
		data=JSON.stringify(data)
		var query=`db.collection(\"${_collection}\").add(${data})`

		var context ={
			"env":this.env,
			"query": query
		}

		var url="https://api.weixin.qq.com/tcb/databaseadd?access_token="+token;
		var result =await got.post(url,{json:context}).catch(err=>{
			console.error(err)
		})
		return result
	}
}

module.exports=new DB()
